<?php

namespace Managers;

class Pages extends BaseManager
{
       protected $__table = '\Catalog\Pages';


    public function getPage($id)
    {

        return $this->_em->createQueryBuilder()
                ->select("s")
                ->from($this->__table, "s")
                ->where("s.id= :id")
                ->setParameter("id", $id)
                ->getQuery()
                ->getArrayResult();
    }

    public  function  getList()

    {

         return $this->_em->createQueryBuilder()
                ->select("s")
                ->from($this->__table, "s")
                ->getQuery()
                ->getArrayResult();
    }
    public function getMenu($ismenu = 1)
    {
           return $this->_em->createQueryBuilder()
                ->select("s.id,s.title,s.url")
                ->from($this->__table, "s")
                ->where("s.ismenu = :ismenu")->setParameter('ismenu', $ismenu)
                ->getQuery()
                ->getArrayResult();
    }
        




    
     public function savePage($title,$content,$menu )
    {

        $page = new \Catalog\Pages();
        $page->setContent($content);
        $page->setTitle($title);
        $page->setIsmenu($menu);
        $this->_em->persist($page);
        $this->_em->flush();
    }

    public function saveEdit($id, $title,$content,$menu )
     {


         $page = $this->_em->find($this->__table, $id);

         if($page) {
         $page->setContent($content);
         $page->setTitle($title);
         $page->setIsmenu($menu);
         $this->_em->persist($page);
         $this->_em->flush();
         return $page;
         }
         return false;
     }





}
